package org.cangku.controller;

import org.cangku.dao.MemberDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberDao memberDao;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(String name,String phone,int offset,int limit){
        Map<String,Object> map = new HashMap<String, Object>();

        map.put("rows",memberDao.query(name,phone,offset,limit));
        map.put("total",memberDao.getCount(name,phone));

        return map;
    }

    @RequestMapping("/getZhekou")
    @ResponseBody
    public Map<String,Object> getZheKou(String phone){
        Map<String,Object> map = new HashMap<String, Object>();

        int i = memberDao.isextentsByPhone(phone);
        if(i>0){
            map.put("zhekou",memberDao.getZheKouByPhone(phone));
        } else{
            map.put("zhekou",0);
        }

        return map;
    }

    /*添加默认数据*/
    @RequestMapping("/insertMoRen")
    @ResponseBody
    public Map<String,Object> insertMoRen(String xm,String sj,String sex){
        Map<String,Object> map = new HashMap<String, Object>();

        int i = memberDao.insertMoRen(xm,sj,sex);
        if(i>0){
            map.put("count",1);
        }else{
            map.put("count",2);
        }

        return map;
    }
}

